/**
 * 
 */
package com.cipe.cmrs.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cipe.cmrs.model.Organizationtype;
import com.cipe.cmrs.model.User;
import com.cipe.cmrs.util.DateUtil;
import com.cipe.cmrs.util.UserUtil;

/**
 * @author Incepio
 * 
 */
@Service
@Transactional
public class OrganizationtypeService extends BaseService<Organizationtype> {

	@Autowired
	private UserService	userService;

	public Organizationtype saveOrganizationtype(Organizationtype organizationtype, Integer userId) {
		if (organizationtype != null) {
			User user = UserUtil.INSTANCE.getCurrentUser();
			Organizationtype dbOrganizationtype = findById(organizationtype.getId());
			if (dbOrganizationtype == null) {
				dbOrganizationtype = new Organizationtype();
				dbOrganizationtype.setCreatedBy(user);
				dbOrganizationtype.setCreationDate(DateUtil.getCurrentDate());
			}
			dbOrganizationtype.setDisplayName(organizationtype.getDisplayName());
			dbOrganizationtype.setDescription(organizationtype.getDescription());
			dbOrganizationtype.setUpdatedBy(user);
			dbOrganizationtype.setUpdationDate(DateUtil.getCurrentDate());
			return merge(dbOrganizationtype);
		}
		return null;
	}
}
